home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / infosrvr / dev / www_talk.930 / 000339_davis@dri.cornell.edu _Wed Nov 18 14:06:19 1992.msg < prev    next >
Internet Message Format  |  1994-01-24  |  5KB

  1. Return-Path: <davis@dri.cornell.edu>
  2. Received: from dxmint.cern.ch by  nxoc01.cern.ch  (NeXT-1.0 (From Sendmail 5.52)/NeXT-2.0)
  3.     id AA08881; Wed, 18 Nov 92 14:06:19 MET
  4. Received: by dxmint.cern.ch (dxcern) (5.57/3.14)
  5.     id AA05803; Wed, 18 Nov 92 14:18:38 +0100
  6. Received: by willow.tc.cornell.edu id AA19290
  7.   (5.65c/IDA-1.4.4 for www-talk@nxoc01.cern.ch); Wed, 18 Nov 1992 08:17:00 -0500
  8. Date: Wed, 18 Nov 1992 08:17:00 -0500
  9. From: Jim Davis <davis@dri.cornell.edu>
  10. Message-Id: <199211181317.AA19290@willow.tc.cornell.edu>
  11. To: www-talk@nxoc01.cern.ch
  12. Subject: a Gateway to the U Mich Geography server
  13.  
  14.  
  15. Here is a quickly hacked up Gateway from WWW to the University
  16. of Michigan Geography server.  It expects one argument, a 
  17. WWW doc id.  It ignores the "pathname", extracts the search words,
  18. then passes those to the server.  It does NOT parse the data
  19. returned by the server (that is an improvment yet to be done)
  20. but you can understand the output.
  21.  
  22. To use this, you would need to have an HTTP server running
  23. someplace where you can attach this gateway.  I can provide
  24. the very simple HTTP server I use here, but this subject
  25. is already documented in the WWW online documentation.
  26.  
  27. Best wishes
  28.  
  29. #!/usr/local/bin/perl
  30. # Gateway from WWW to the Geography server at U Michigan
  31. # Copyright 1992 Xerox.  All rights reserved.
  32. # This program is distributed in the hope that it will be useful,
  33. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  35. # Jim Davis, Nov 17 1992
  36.  
  37. # To do:
  38. # 1) Parse the returned info so as to display more neatly.
  39. #    (See documentation at end of file its format.)
  40. # 2) Handle case where multiple places match supplied name
  41. # 3) Handle case where no place matches supplied name.
  42.  
  43. # This expects one argument, a document ID.  The search keywords
  44. # are sent to the Geography server, the "pathname" is ignored.
  45. # e.g. /geography/ignored/whocares?ithaca,ny => ithaca,ny
  46. # As an extra bonus feature, if the first arg has no question marks
  47. # then the entire arg line is passed to the server.  This is
  48. # convenient when you call this from the shell rather than from WWW.
  49.  
  50. if ($#ARGV == -1) {
  51.  die "Usage: geography-gateway [WWW-DOCUMENT-ID | location]\
  52. An example WWW document id is /geography?washington,dc
  53. If calling from shell, omit the /geography? part.\nStopped";}
  54.  
  55. $usage =  "<ISINDEX>\n\
  56. <TITLE>Geography Server</TITLE>\n\
  57. <h2>Type geographic name in Index.</h2>\n\
  58. ";
  59.  
  60. # for debugging
  61. # print "<LISTING>\n";
  62. # print "ARGV =  $#ARGV\n";
  63. # for ($i = 0; $i < $#ARGV+1; $i++) {
  64. #   print "Arg $i is $ARGV[$i]\n";}
  65. # print "</LISTING>";
  66. # exit;
  67.  
  68.  
  69. @parts=split('/', $ARGV[0]);  # separate pathname from keywords.
  70. $last = $parts[$#parts];      # the last path component has keys
  71. $i=index($last,"?");          # are there any keywords in there?
  72. if ($i == -1)
  73.    {@keywords = @ARGV;}          # none, probably called from shell
  74.  else
  75.    {@keywords=split('\?', substr($last,$i));
  76.     $parts[$#parts] = substr($last,0,$i);}
  77.  
  78.  
  79. # if no keywords, tell user how to type them.
  80.  
  81. if ($#keywords == -1) {
  82.   print $usage;
  83.   exit;
  84.   };
  85.  
  86.  
  87. # debugging
  88. # print "<LISTING>\n
  89. # parts are @parts\n
  90. # keywords are @keywords\n
  91. # </LISTING>\n";
  92. # exit;
  93.  
  94. # otherwise contact the server
  95.  
  96. $host = "martini.eecs.umich.edu";
  97. $port = 3000;
  98.  
  99. $sockaddr = 'S n a4 x8';         # packing format
  100.  
  101. $hostname = `hostname`;          # where I am calling from
  102. chop($hostname);                 # get rid of trailing CR
  103. ($name, $aliases, $type, $len, $myaddr) = gethostbyname($hostname);
  104. $here = pack($sockaddr, 2, 0, $myaddr);
  105.  
  106. ($name, $aliases, $type, $len, $destaddr) = gethostbyname($host);
  107.  
  108. #print ("Name = ", $name ," " addr = ", $destaddr, "\n");
  109. if ($destaddr eq "") {die "No such host: $host. Stopped";}
  110.  
  111. $there= pack($sockaddr, 2, $port, $destaddr);
  112.  
  113. ($name, $aliases, $protocol) = getprotobyname('tcp');
  114. socket($S, 2, 1, $protocol) || die "socket: $!";
  115. bind ($S, $here) || die "bind: $!";
  116. connect ($S, $there) || die "connect: $!";
  117.  
  118.  
  119. select($S);
  120. $| = 1;           # force output
  121. print (@keywords ,"\n");
  122. print "quit\n";
  123. select(STDOUT);
  124. print "<LISTING>\n";
  125. while (<$S>) { print;}
  126. print "</LISTING>\n";
  127. select($S);
  128. exit;
  129.  
  130. # This is the format of info returned by the geo server.
  131. # in case you decide you want to parse it.
  132.  
  133. # 0 <city name>
  134. # 1 <county FIPS code> <county name>
  135. # 2 <state/province abbreviation> <state/province name>
  136. # 3 <nation abbreviation> <nation name>
  137. # A <telephone area code>
  138. # E <elevation in feet above mean sea level>
  139. # F <feature code> <feature name>
  140. # L <latitude DD MM SS X> <longitude DDD MM SS X>
  141. # P <1980 census population>
  142. # R <remark>
  143. # T <time zone>
  144. # Z <postal ("ZIP") code>
  145.  
  146. # Example
  147. # 0 Ithaca
  148. # 1 36109 Tompkins
  149. # 2 NY New York
  150. # 3 US United States
  151. # R county seat
  152. # F 45 Populated place
  153. # L 42 26 26 N  76 29 49 W
  154. # P 28732
  155. # E 814
  156. # Z 14850 14851 14852 14853 14882
  157. # .